<script type="text/javascript">

    $(document).ready(function(){

        $("#btn_pilih_lokasi").click(function(){
            $("#dialog-lokasi").dialog('open');
        });
        
        $("#btn_pilih_barang").click(function(){
            $("#dialog-barang").dialog('open');
        });

    });
    
    function PilihLokasi(aa){
        var cc=aa.split("#");
        $("#kode_png").val(cc[0]);
        $("#nama_png").val(cc[1]);           
        $("#dialog-lokasi").dialog('close');
    }
               
    function PilihBarang(aa){
        var cc=aa.split("#");
            
        $("#kode_aset").val(cc[0]);
        $("#nama_kel").val(cc[1]);
        $("#dialog-barang").dialog('close');
    }
        
        
</script>


<div class="form">

<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
    'id' => 'horizontalForm',
    'type' => 'horizontal',
    'enableAjaxValidation' => false,
        ));
 ?>

	<p class="note">Fields with <span class="required">*</span> are required.</p>

	<?php echo $form->errorSummary($model); ?>

    <div class="control-group ">
        <label class="control-label" >Kode KIC</label>
        <div class="controls">
		
            <?php
            $query = "select max(kode_kc) as kode from kib_c";

            $hasil = Yii::app()->db->createCommand($query)->queryRow();

            if ($hasil['kode'] == 0) {
                $kode = $hasil['kode'] = 1;
            } else {
                $kode = $hasil['kode'] + 1;
            }

            echo $form->textField($model, 'kode_kc', array('class' => 'span1', 'id' => 'kode', 'value' => $kode, 'readonly' => true, 'maxlength' => 10));
            ?>
		</div>
	</div>

        <div class="control-group ">
            <label class="control-label" >Kode Pengelola</label>
            <div class="controls">
                <div class="span3" style="margin-left:0;">
                <div class="input-group">
                    <?php echo $form->textField($model, 'kode_png', array('class' => 'form-control', 'id' => 'kode_png', 'maxlength' => 20));  ?>
                    <span class="input-group-btn">	
                        <?php
                        $this->widget('bootstrap.widgets.TbButton', array(
                            'type' => 'info',
                            'label' => 'F1',
                            'htmlOptions' => array('id' => 'btn_pilih_lokasi')
                        ));
                        ?>
                    </span>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="control-group ">
            <label class="control-label"></label>
            <div class="controls">
                <input type="text" class="span4" id="nama_png">
            </div>
        </div>        
        
        <div class="control-group ">
            <label class="control-label" ><b>Kode Barang</b></label>
            <div class="controls">
                <div class="span3" style="margin-left:0;">
                    <div class="input-group">
                        <?php echo $form->textField($model, 'kode_aset', array('class' => 'form-control', 'id' => 'kode_aset', 'maxlength' => 25)); ?>
                        <span class="input-group-btn">	
                        <?php
                            $this->widget('bootstrap.widgets.TbButton', array(
                            'type' => 'info',
                            'label' => 'F2',
                            'htmlOptions' => array(
                            'id' => 'btn_pilih_barang',
                            'style' => 'padding-left:15px;',
                            )
                            ));
                        ?>
                        </span>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="control-group ">
        <label class="control-label" >Nama Barang</label>
            <div class="controls">
                <input type="text" class="span4" id="nama_kel">
            </div>
        </div>        

	<div class="control-group">
		<label class="control-label">Nomor Register</label>
		<div class="controls">
		<?php echo $form->textField($model,'no_reg',array('size'=>25,'maxlength'=>25)); ?>
	</div>

	<div class="control-group">
		<label class="control-label">Kondisi</label>
		<div class="controls">
                      <?php
                      echo $form->dropDownList($model, 'tingkat', array(
                            'prompt' => '',
                            '0' => 'B',
                            '1' => 'R',
                            '1' => 'RB',
                        ), array('class' => 'span2', 'id' => 'kode', 'maxlength' => 5));
                 ?>
            </div>
	</div>

	<div class="control-group">
            <label class="control-label">Tingkat</label>
            <div class="controls">
                 <?php
                      echo $form->dropDownList($model, 'tingkat', array(
                            'prompt' => '',
                            '0' => 'Ya',
                            '1' => 'Tidak',
                        ), array('class' => 'span2', 'id' => 'kode', 'maxlength' => 5));
                 ?>
            </div>
	</div>

	<div class="control-group">
            <label class="control-label">Beton</label>		
            <div class="controls">
                 <?php
                      echo $form->dropDownList($model, 'beton', array(
                            'prompt' => '',
                            '0' => 'Ya',
                            '1' => 'Tidak',
                        ), array('class' => 'span2', 'id' => 'kode', 'maxlength' => 5));
                 ?>
            </div>
	</div>

	<div class="control-group">
		<label class="control-label">Luas Lantai</label>
		<div class="controls">
		<?php echo $form->textField($model,'luas_tnh',array('size'=>16,'maxlength'=>16)); ?>
	</div>

	<div class="control-group">
		<label class="control-label">Alamat</label>
		<div class="controls">
		<?php echo $form->textField($model,'alamat',array('size'=>100,'maxlength'=>100)); ?>
	</div>

	<div class="control-group">
        <label class="control-label" >Tanggal Dokumen</label>
        <div class="controls">
            <div class="span2" style="margin:0;">
                <div class="input-group">
                    <span class="input-group-addon"><i class="icon-calendar"></i></span>
                    <?php
                    $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                        'model' => $model,
                        'attribute' => 'tgl_dok',
                        'options' => array(
                        'yearRange' => 'c-50:c+20',
                        ),
                    ));
                    ?>
                </div>
            </div>	
        </div>
	</div>

	<div class="control-group">
		<label class="control-label">Luas Tanah</label>
                <div class="controls">
                    <?php echo $form->textField($model, 'luas_tnh', array('class' => 'span3', 'id' => 'kode', 'maxlength' => 50)); ?>
                </div>
	</div>

	<div class="control-group">
		<label class="control-label">Status Tanah</label>
		<div class="controls">
		<?php echo $form->textField($model,'status_tanah',array('size'=>16,'maxlength'=>16)); ?>
	</div>

	<div class="control-group">
		<label class="control-label">Kode Tanah</label>
		<div class="controls">
		<?php echo $form->textField($model,'kode_tnh',array('size'=>16,'maxlength'=>16)); ?>
	</div>

	<div class="control-group">
		<label class="control-label">Asal</label>
		<div class="controls">
		<?php echo $form->textField($model,'asal',array('size'=>25,'maxlength'=>25)); ?>
	</div>

	<div class="control-group">
		<label class="control-label">Harga Perolehan</label>
		<div class="controls">
		<?php echo $form->textField($model,'harga_prh',array('size'=>16,'maxlength'=>16)); ?>
	</div>

	<div class="control-group">
		<label class="control-label">Harga Pasar</label>
		<div class="controls">
		<?php echo $form->textField($model,'harga_pasar',array('size'=>16,'maxlength'=>16)); ?>
	</div>

	<div class="control-group">
		<label class="control-label">Keterangan</label>
		<div class="controls">
		<?php echo $form->textField($model, 'keterangan', array('class' => 'span4', 'id' => 'kode', 'maxlength' => 200)); ?>
	</div>

	<div class="control-group">
        <label class="control-label" >Kode Milik</label>
        <div class="controls">
            <?php
                echo $form->dropDownList($model, 'kode_milik', array(
                'prompt' => '',
                '0' => 'Kabupaten/Kota',
                '1' => 'Propinsi',
                '2' => 'Negara',
                ), array('class' => 'span2', 'id' => 'kode', 'maxlength' => 50));
            ?>
            </div>
	</div>

        <div class="form-actions">
        <?php
            $this->widget('bootstrap.widgets.TbButton', array(
                'buttonType' => 'submit',
                'type' => 'success',
				'icon' => 'save',
				'label' => 'Simpan',
            ));
            ?>
            <?php
            $this->widget('bootstrap.widgets.TbButton', array(
            'type' => 'primary',
            'label' => 'Cari',
			'icon' => 'search',
			'url' => Yii::app()->createUrl("/KIB/KibC/admin"),
			'htmlOptions' => array(
				'style' => 'margin-left:5px',
			),
            ));
            ?>
            <?php
            $this->widget('bootstrap.widgets.TbButton', array(
                'buttonType' => 'reset',
				'icon' => 'remove',
				'label' => 'Batal',
				'htmlOptions' => array(
					'style' => 'margin-left:5px;',
				),
                ));
            ?>


<?php $this->endWidget(); ?>
            
<!-- PERINTAH UNTUK MENAMPILKAN PENCARIAN DATA -->
</div><!-- form -->
    <?php
    $this->beginWidget('zii.widgets.jui.CJuiDialog', array(
        'id' => 'dialog-lokasi',
        'options' => array(
            'title' => 'Cari Data Lokasi',
            'overflow' => 'scroll',
            'width' => 900,
            'height' => 500,
            'autoOpen' => false,
        ),
    ));
    ?>

<?php
Yii::app()->clientScript->registerScript('pengelola', "
			$('form#pengelola').submit(function(){
				$.fn.yiiGridView.update('Pengelola', {
					data: $(this).serialize()
				});
				return false;
			});
		
		");
?>

<form method="get" class="form-horizontal" action="<?php echo Yii::app()->createUrl($this->route); ?>" id="pengelola">
    <div class="alert alert-info">
        <div class="control-group">
            <label class="control-label">Kode Pengelola </label>
            <div class="controls">
                <input type="text" class="span3" name="Pengelola[kode_skpd]" id="pengelola_kode_skpd" /> 
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">Nama Pengelola </label>
            <div class="controls">    
                <input type="text" class="span3" name="Pengelola[nama_png]" id="pengelola_nama_png" />
            </div>
        </div>

<?php
$this->widget('bootstrap.widgets.TbButton', array(
    'buttonType' => 'submit',
    'icon' => 'search',
    'htmlOptions' => array(
        'id' => 'btn_search',
        'style' => 'margin-left:20px;',
    ),
    'label' => 'Cari',
));
?>
    </div>
</form>


        <?php
        $this->widget('bootstrap.widgets.TbGridView', array(
            'id' => 'Pengelola',
            'dataProvider' => $modelPengelola->search(),
            'type' => 'striped bordered condensed',

            'columns' => array(
                array(
                    'header' => 'Kode Pengelola',
                    'value' => '$data->kode_skpd',
                ),
                array(
                    'header' => 'Nama Pengelola',
                    'value' => '$data->nama_png',
                ),

                array(
                    'value' => 'CHtml::Button("Pilih",
                array("onClick" => "PilihLokasi(\'".$data->kode_png."#".
                $data->nama_png."\'
                )",
				"class"=>"btn btn-info",
				))',
                    'type' => 'raw',
                    'htmlOptions' => array(
                        'style' => 'text-align:center',
                    ),
                ),
            ),
        ));
  
        ?>
 

<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>


<!-- begin dialog-barang -->
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
    'id' => 'dialog-barang',
    'options' => array(
        'title' => 'Cari Data Barang',
        'overflow' => 'scroll',
        'width' => 900,
        'height' => 500,
        'autoOpen' => false,
    ),
));
?>

<?php
Yii::app()->clientScript->registerScript('barang', "
			$('form#barang').submit(function(){
				$.fn.yiiGridView.update('Barang', {
					data: $(this).serialize()
				});
				return false;
			});
		
		");
?>

<form method="get" class="form-horizontal" action="<?php echo Yii::app()->createUrl($this->route); ?>" id="barang">
    <div class="alert alert-info">
        <div class="control-group">
            <label class="control-label">Kode Barang </label>
            <div class="controls">
                <input type="text" class="span3" name="KelAset[kode_aset]" id="KelAset_kode_aset" /> 
            </div>
        </div>

        <div class="control-group">
            <label class="control-label">Nama Lokasi </label>
            <div class="controls">    
                <input type="text" class="span3" name="KelAset[nama_kel]" id="KelAset_nama_kel" />
            </div>
        </div>

<?php
$this->widget('bootstrap.widgets.TbButton', array(
    'buttonType' => 'submit',
    'icon' => 'search',
    'htmlOptions' => array(
        'id' => 'btn_search',
        'style' => 'margin-left:20px;',
    ),
    'label' => 'Cari',
));
?>
    </div>
</form>



        <?php
        $this->widget('bootstrap.widgets.TbGridView', array(
            'id' => 'Barang',
            'dataProvider' => $modelKelAset->KibA(),
            'type' => 'striped bordered condensed',

            'columns' => array(
                array(
                    'header' => 'Gol',
                    'value' => '$data->gol',
                ),
                array(
                    'header' => 'Bid',
                    'value' => '$data->bid',
                ),
                array(
                    'header' => 'Kel',
                    'value' => '$data->kel',
                ),
                array(
                    'header' => 'Sub Kel',
                    'value' => '$data->subkel',
                ),
                array(
                    'header' => 'Nama Barang',
                    'value' => '$data->nama_kel',
                ),
                array(
                    'header' => 'Kode Barang',
                    'value' => '$data->kode_aset',
                ),

                array(
                    'value' => 'CHtml::Button("Pilih",
                array("onClick" => "PilihBarang(\'".$data->kode_aset."#".
                $data->nama_kel."\'
                )",
				"class"=>"btn btn-info",
				))',
                    'type' => 'raw',
                    'htmlOptions' => array(
                        'style' => 'text-align:center',
                    ),
                ),
            ),
        ));
        ?>

<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>